<template>
    <div>
      <van-goods-action class="btn">
          <van-goods-action-icon 
          :icon="isCollected?'star':'star-o'" 
          :text="isCollected?'已收藏':'未收藏'" 
          :color="isCollected?'darkred':'#333'" 
          @click="isCollected = !isCollected"  /> 
          <van-goods-action-icon @click="goCart" icon="cart-o" text="购物车" :badge="goodsCount" color="#333"/>
          <van-goods-action-button @click="addCar()" type="warning" text="加入购物车" />
          <van-goods-action-button type="danger" text="立即购买" />
      </van-goods-action>
  </div>
  </template>
  
  <script>
  import {AddGWC,GetGWC} from '@/request/api'
  export default {
      data(){
          return{
              isCollected:false,
              goodsCount:0
          }
      },
      props:['goodsId','productId'],
      created(){
        // console.log(this.goodsId);
        // console.log(this.productId);
        this.addCar()
        this.getCarNum()
      },
      methods:{
          async addCar(){
          // console.log(this.goodsId,this.productList)
            let res=  await AddGWC({
              goodsId:this.goodsId,
              productId:this.productId,
              number:1
            })
            this.getCarNum()
            // console.log(res)
          },
          async getCarNum(){
            let res= await GetGWC()
            // console.log(res)
            if(res.errno==0){
              this.goodsCount=res.data.cartTotal.goodsCount
            }
          },
          goCart(){
            this.$router.push('/cart')
          }
      }
  }
  </script>
  
  <style lang="less">
  .btn{
    width: 100%;
  }
  </style>